<template>
  <div style="width:50%;text-align:center;margin:auto;">
    <el-form ref="dataForm" :rules="rules" :model="getUser" label-position="left" label-width="110px" style="margin-left:50px; margin-right:50px;">
      <el-form-item label="新密码" prop="PassWord">
        <el-input v-model.trim="getUser.PassWord" type="password" placeholder="请输入新的密码" @keyup.enter.native="createData" />
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button @click="$emit('dialogPasswordVisibleEmit', false)">
        取消
      </el-button>
      <el-button type="primary" :loading="loading" @click="createData">
        确认
      </el-button>
    </div>
  </div>
</template>

<script>
import { validatePassword } from '@/utils/validator'
export default {
  name: 'PassWordForm',
  props: {
    user: { type: Object, default: Object }
  },
  data() {
    return {
      loading: false,
      rules: {
        PassWord: [{ required: true, trigger: 'blur', validator: validatePassword }]
      }
    }
  },
  computed: {
    getUser() {
      // eslint-disable-next-line vue/no-side-effects-in-computed-properties
      this.user.PassWord = ''
      return this.user
    }
  },
  methods: {
    createData() {
      this.$refs['dataForm'].validate(valid => {
        if (valid) {
          this.$emit('createPassword', this.user)
        }
      })
    }
  }
}
</script>
